package com.info.zhiduoduo.repository.mapper.maker;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.info.zhiduoduo.repository.dto.complaint.ComplaintDto;
import com.info.zhiduoduo.repository.entity.complaint.Complaint;

import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author bob
 * @since 2019-12-26
 */
public interface ComplaintMapper extends BaseMapper<Complaint> {

	@Select(" select co.*,sm.managername,sm1.managername as addAdminName " +
			" from zdd_complaint co " +
			" left join zdd_system_manager sm on sm.managerid = co.reply_manager_id " +
			" left join zdd_system_manager sm1 on sm1.managerid = co.add_adminid " +
			" where IF(#{userType}=0, 1=1, co.user_type=#{userType}) " +
			" and co.username like '%${name}%' " +
			" and IF(ISNULL(#{needReply}), 1=1, co.need_reply=#{needReply}) " +
			" and IF(ISNULL(#{hasReply}), 1=1, co.has_reply=#{hasReply}) " +
			" and co.deleted = 0 " +
			" order by co.id desc ")
	List<ComplaintDto> getList(int userType, String name, Integer needReply, Integer hasReply);

	@Select(" select co.*,sm.managername,sm1.managername as addAdminName " +
			" from zdd_complaint co " +
			" left join zdd_system_manager sm on sm.managerid = co.reply_manager_id " +
			" left join zdd_system_manager sm1 on sm1.managerid = co.add_adminid " +
			" where co.userid = #{userid} " +
			" and co.user_type = #{userType} " +
			" and co.username like '%${name}%' " +
			" and IF(ISNULL(#{needReply}), 1=1, co.need_reply=#{needReply}) " +
			" and IF(ISNULL(#{hasReply}), 1=1, co.has_reply=#{hasReply}) " +
			" and co.deleted = 0 " +
			" order by co.id desc ")
	List<ComplaintDto> getListByUserid(int userid, int userType, String name, Integer needReply, Integer hasReply);

	@Select(" select co.*,sm.managername,sm1.managername as addAdminName " +
			" from zdd_complaint co " +
			" left join zdd_system_manager sm on sm.managerid = co.reply_manager_id " +
			" left join zdd_system_manager sm1 on sm1.managerid = co.add_adminid " +
			" where co.id = #{id} ")
	ComplaintDto getDetail(int id);
}
